<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@page import="com.framework.entity.Global"%>
<%@ page import="com.biz.utils.ConfigUtil" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
    String resoursUrl = ConfigUtil.get("RESOURCES_URL");
%>
<!DOCTYPE html>
<html class="no-js">
<head>
  <meta charset="UTF-8">
  <title >退款详情</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="format-detection" content="telephone=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <jsp:include page="/jsp/inc_head.jsp"></jsp:include>
  <script src="assets/js/TouchSlide.1.1.source.js"></script>
</head>
<body>
<section class="am-g am-text-sm">
	<div class="am-u-sm-12 sqtkTopDivTwo" id="refund_state">
    
    </div>
    <div class="fenge"></div>
    <div class="am-u-sm-12 sqtkDdxx" id="countdown">
    
    </div>
    <div class="am-u-sm-12 am-padding-0" id="order_detailList">
      
    </div>
    <div class="fenge"></div>
    <div class="am-u-sm-12 thtkSjtyXq">
    	<div class="am-u-sm-12" id="refund_money">
        	
        </div>
    	<div class="am-u-sm-12" id="personName">
        	
        </div>
    	<div class="am-u-sm-12" id="phone">
        	
        </div>
    	<div class="am-u-sm-12" id="refund_note">
        	
        </div>
    	<div class="am-u-sm-12" id="refund_pics">
        	
        </div>
    </div>
</section>

<!--footer-->
<div class="am-g gdDbdiv"></div>
<div id=refund_button>

</div>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
	<div class="am-modal-dialog">
		<div class="am-modal-hd" id="alert_title">哎呦喂，出错啦</div>
		<div class="am-modal-bd" id="alert_message"></div>
		<div class="am-modal-footer">
			  <span class="am-modal-btn">确定</span>
		</div>
	</div>
</div>
<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert2">
	<div class="am-modal-dialog">
		<div class="am-modal-hd" id="alert_title2"></div>
		<div class="am-modal-bd" id="alert_message2"></div>
		<div class="am-modal-footer" id="alert_button2">
			 
		</div>
	</div>
</div>
<script>
var ajaxpath="${pageContext.request.contextPath}";
var picPath_goods='<%=Global.OSSURL%>/';
var picPath_goodsType3='<%=Global.OSSURL_MAINTYPE3%>/';
var endTime='<%=Global.REFUNDTIME%>';
var timer;  
var s=0;
var djs=0;
var type='${type}';
$(function() {
//loadOrderInfo();
loadUserInfo();
loadOrderInfo();


});

function loadUserInfo()
{
var url=ajaxpath+'/userCenter/queryMyInfo.do?orderId=${id}';
 	$.get(url, function(result){
 	$("#personName").html("联系人  "+result.personName);
 	$("#phone").html("联系电话  "+result.phone);
 	});
}
function loadOrderInfo()
{

 var url=ajaxpath+'/order/getOrderInfoForDetail.do?id=${refund}';
 
 	$.get(url, function(result){ 	
 	var data=JSON.parse(result);
 	
 	$("#refund_note").html('退款原因 '+data.note);
 	$("#refund_money").html('退款金额  <span class="colred">￥  '+data.money+'</span>');
 	
 	var createTime=new Date(data.createTime.replace(/-/g, "/"));
 	var today=new Date();

 	var timeleft=accMul(endTime,86400000);
 	//计算剩余时间
 	var timesy=accSub(timeleft,accSub(today.getTime(),createTime.getTime()));
 	s=accDiv(timesy,1000);
 	var day=Math.floor(accDiv(accDiv(timesy,1000),86400)); 	
 	timesy=accSub(timesy,accMul(day,86400000));
	var hou=Math.floor(accDiv(accDiv(timesy,1000),3600));
	timesy=accSub(timesy,accMul(hou,3600000));
	var min=Math.floor(accDiv(accDiv(timesy,1000),60));
	timesy=accSub(timesy,accMul(min,60000));
	var sec=Math.floor(accDiv(timesy,1000));
	if(data.pics.length>0){
 	var html='<div class="am-u-sm-12 am-padding-0 am-margin-bottom-xs">图片</div>';
 	$(data.pics).each(function(i){
		var urls = '';
		if(data.pics[i].mainType == '3')
		{
			urls =picPath_goodsType3+data.pics[i].path;
		}else{
			urls =picPath_goods+data.pics[i].path;
		}
 	html+='<div class="am-u-sm-3 am-padding-0 am-u-end"><img src="'+urls+'" class="thtkImg"></div>';
 	});
 	$("#refund_pics").html(html);
	}
 	doDeails(data.orders);
 	var htmlbutton='';
 	var htmltop='';
 	var htmltop2=''; 	
 	if(data.state=='1')
 	{htmlbutton='<a onclick="clearRefund()" class="botBtn sqtkCxsq" >撤销申请</a>'+
 	'<a href="<%=basePath %>order/toOrderRefundForEdit.do?refundId=${refund}&type=1" class="botBtn yellowBtn">修改申请</a>';
 	htmltop='<img src="<%=resoursUrl%>resources/assets/images/sqtkddz.png" width="30" />&nbsp;<span class="am-text-middle">等待中</span>';
   htmltop2='若<span class="colred" id="leftday">'+day+'</span> 天<span class="colred" id="lefthou">'+hou+'</span> 时<span class="colred" id="leftmin">'+min+'</span> 分'+
   '<span class="colred" id="leftsec">'+sec+'</span> 秒内申请未处理，退款申请将达成并原路退回';
    }
 	else if(data.state=='3')
 	{
 	htmlbutton='<a href="javascript:history.back(-1)" class="botBtn sqtkCxsq" >返回</a>'+
 	'<a href="<%=basePath %>order/toOrderRefundForEdit.do?refundId=${refund}&type=2" class="botBtn yellowBtn" >重新申请</a>';
 	htmltop='<img src="<%=resoursUrl%>resources/assets/images/sqtkyjj.png" width="30" />&nbsp;   <span class="am-text-middle">退款失败</span>';
    htmltop2='卖家拒绝：'+data.remarks;
 	}
 	else  if(data.state=='2')
 	{
 	htmlbutton='<a href="javascript:history.back(-1)" class="footeNavbar botBtn">返回</a>';
 	htmltop='<img src="<%=resoursUrl%>resources/assets/images/sqtkyty.png" width="30" />&nbsp;   <span class="am-text-middle">退款成功</span>';
    
 	}
 	$("#countdown").html(htmltop2);
$("#refund_state").html(htmltop);
$("#refund_button").html(htmlbutton);
 timer=setInterval("clock()",1000); 
});
 }
 
 function toList()
 {
  window.location.href = ajaxpath+"/jsp/order/orderList.jsp"; 
 }
 function clearRefund()
 {
  var url=ajaxpath+'/order/clearRefund.do?id=${id}';
 //alert(url);
 	$.get(url, function(result){ 	
 	var res=JSON.parse(result);
 	  if(res.flag=="success")
             {
             	 $("#alert_message2").html("申请成功！");
			
				var html= '<span class="am-modal-btn" onclick="toList()">确定</span>';
				 $("#alert_button2").html(html);
					$("#my-alert2").modal('open');
             }
             else
             {	
              $("#alert_message").html(res.flag);
				$("#my-alert").modal('open');
             }
 	}); 
 }
function  doDeails(data)
{
var html='';//商品信息
var payTotal=0;
var feiTotal=0;
 $(data).each(function(i){

payTotal=accAdd(payTotal,accMul(data[i].count,data[i].detailPayTotal));
feiTotal=accAdd(feiTotal,data[i].detailfreightTotal);
 html+='<div class="am-u-sm-12 orderinfo">'+
 		'<div class="am-u-sm-3 am-padding-0">';
	 if(data[i].mainType == '3')
	 {
		 html+= '<img src="<%=Global.OSSURL_MAINTYPE3%>/'+data[i].goodsPath+'" class="sptpimg" />' ;
	 }else{
		 html+= '<img src="<%=Global.OSSURL%>/'+data[i].goodsPath+'" class="sptpimg" />' ;
	 }
	 html+= '</div>'   +
            '<div class="am-u-sm-9 am-padding-0" >'    +
            '<div class="am-u-sm-12 am-padding-0 infoname">'+data[i].goodsName+'</div>'+
            '<div class="am-u-sm-12 infogg">'+data[i].typeValue1;
            if(data[i].typeValue2 != undefined)
            {
            	html+= ','+data[i].typeValue2;
            }
             if(data[i].typeValue3 != undefined)
            {
            	html+= ','+data[i].typeValue3;
            }
           html +='</div>';
           html+= '<div class="am-u-sm-12 am-padding-0" style="font-size:13px;">'   +
            '<div class="am-u-sm-6 am-padding-0">X'+data[i].count+'</div>'   +
            ' <div class="am-u-sm-6 am-padding-0 am-text-right">￥'+toDecimal2(data[i].price)+'</div>'+
            ' </div></div></div>';    
 });
 var htmlEnd=  ' </div>'+
          '<div class="am-u-sm-12 ddxqSfyf">' +
          
          '实付：<span class="colred">￥<span>'+toDecimal2(payTotal)+'</span> </span> &nbsp;'+
        	'<span class="ddxqSfyfYf" style="display: none">(运费 ￥<span>'+toDecimal2(feiTotal)+'</span>)</span>'+
             '</div></div>' ; 
 $("#order_detailList").html(html+htmlEnd);
}
 
 
 function accAdd(arg1,arg2){  //浮点数运算加法
    var r1,r2,m;  
    try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;}  
    try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;}  
    m=Math.pow(10,Math.max(r1,r2))  ;
    return (arg1*m+arg2*m)/m  ;
}
//浮点数运算乘法
function accMul(arg1,arg2)  
{  
    var m=0,s1=arg1.toString(),s2=arg2.toString();  
    try{m+=s1.split(".")[1].length;}catch(e){}  
    try{m+=s2.split(".")[1].length;}catch(e){}  
    return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m) ; 
}
//浮点数运算减法
function accSub(arg1,arg2){      
    return accAdd(arg1,-arg2);  
}

//浮点数运算除法
function accDiv(arg1,arg2){  

    var t1=0,t2=0,r1,r2;  
    try{t1=arg1.toString().split(".")[1].length;}catch(e){}  
    try{t2=arg2.toString().split(".")[1].length;}catch(e){}  
	
    with(Math){  
        r1=Number(arg1.toString().replace(".",""))  ;
        r2=Number(arg2.toString().replace(".",""))  ;

        return (r1/r2)*pow(10,t2-t1);  
    }  
}
function toDecimal2(x) {  
            var f = parseFloat(x);  
            if (isNaN(f)) {  
                return 0.00;  
            }  
            var f = Math.round(x*100)/100;  
            var s = f.toString();  
            var rs = s.indexOf('.');  
            if (rs < 0) {  
                rs = s.length;  
                s += '.';  
            }  
            while (s.length <= rs + 2) {  
                s += '0';  
            }  
            return s;  
        }
        
        
   /////////////////////////////////////////////////////倒计时
  function clock(){  
     /*s是clock()中的变量，非var那种全局变量，代表剩余秒数*/  
   // alert(s);
   /*   this.move=function(){  */ 
         /*输出前先调用exchange函数进行秒到分秒的转换，因为exchange并非在主函数window.onload使用，因此不需要进行声明*/  
        // document.getElementById("timer").innerHTML=exchange(this.s);  
 
        exchange(s);       
         /*每被调用一次，剩余秒数就自减*/  
         s=s-1;
	  if(type==0)
	  { djs=djs+1;
		  if(djs>=5)
		  { window.location.href = ajaxpath+"/client_toHomeScreen.do";
		  }
	  }

         /*如果时间耗尽，那么，弹窗，使按钮不可用，停止不停调用clock函数中的move()*/  
         if(s<0){  
           //  alert("支付已超时！");  
             //windowsurl();
            // ljgoumai
            // $("#ljgoumai").attr("disabled",true); 
              //$("#ljgoumai").attr("class","btncancel");
            //document.getElementById("go").disabled=true;  
             clearTimeout(timer);  
             }  
       //  }  
     }  
     
      function exchange(timesy){  
     /*javascript的除法是浮点除法，必须使用Math.floor取其整数部分*/  
       /*   var min=Math.floor(time/60);  
         /*存在取余运算  
         var sen=(time%60);  
        $("#min_time").html(min);
        $("#sen_time").html(sen); 
         /*传过来的形式参数time不要使用this，而其余在本函数使用的变量则必须使用this*/  
        // return this.text; 
        	var day=Math.floor(accDiv(timesy,86400)); 	
		 	timesy=accSub(timesy,accMul(day,86400));
			var hou=Math.floor(accDiv(timesy,3600));
			timesy=accSub(timesy,accMul(hou,3600));
			var min=Math.floor(accDiv(timesy,60));
			timesy=accSub(timesy,accMul(min,60));
			var sec=Math.floor(timesy); 
			$("#leftday").html(day);
			$("#lefthou").html(hou);
			$("#leftmin").html(min);
			$("#leftsec").html(sec);
			
 }  
  
 <%-- 
   <div class="am-u-sm-12 orderinfo">
            <div class="am-u-sm-3 am-padding-0">
                <img src="<%=basePath %>resources/assets/images/xqxqpic.png" class="sptpimg" />
            </div>
            <div class="am-u-sm-9 am-padding-0">
                <div class="am-u-sm-12 am-padding-0 infoname">33朵卡罗拉66朵香槟珍爱久久节日</div>
                <div class="am-u-sm-12 infogg">苏醒，0枝</div>
                <div class="am-u-sm-12 am-padding-0" style="font-size:13px;">
                    <div class="am-u-sm-6 am-padding-0">X1</div>
                    <div class="am-u-sm-6 am-padding-0 am-text-right">￥ 199.00</div>
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 orderinfo">
            <div class="am-u-sm-3 am-padding-0">
                <img src="<%=basePath %>resources/assets/images/xqxqpic.png" class="sptpimg" />
            </div>
            <div class="am-u-sm-9 am-padding-0">
                <div class="am-u-sm-12 am-padding-0 infoname">33朵卡罗拉66朵香槟珍爱久久节日</div>
                <div class="am-u-sm-12 infogg">苏醒，0枝</div>
                <div class="am-u-sm-12 am-padding-0" style="font-size:13px;">
                    <div class="am-u-sm-6 am-padding-0">X1</div>
                    <div class="am-u-sm-6 am-padding-0 am-text-right">￥ 199.00</div>
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 ddxqSfyf">
        	实付：￥199.00 &nbsp;
            <span class="ddxqSfyfYf">(运费 ￥10.00)</span>
        </div> --%>
</script>
</body>
</html>


